package com.alog.yzd.jdbc.hm;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DaoFactory {
    private static DaoFactory instance = new DaoFactory();
    private UserDao mUserDao;
    private DaoFactory(){
        try {
            Properties prop = new Properties();
            InputStream in = new FileInputStream(new File("daoconfig.properties"));
            prop.load(in);
            String userDaoClass = prop.getProperty("UserDaoClass");
            mUserDao = (UserDao) Class.forName(userDaoClass).newInstance();
        } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new ExceptionInInitializerError(e.getMessage());
        }
    }

    public static DaoFactory getInstance(){
        return instance;
    }

    public UserDao getUserDao(){
        return mUserDao;
    }

}
